//
// Created by Gorun on 2022/5/1.
//

#include "Token.h"
#include <string>

Token::Token(TokenType type, const std::string& lexeme, const Object* literal,
             int line, int column) {
    this->type=type;
    this->lexeme=lexeme;
    this->literal=literal;
    this->line=line;
    this->column=column;
}

Token::~Token() {
    delete literal;
}

const char* getTypeStr(TokenType type) {
    return type_str[static_cast<int>(type)];
}

std::string Token::toString() {
    return std::string (getTypeStr(type))+' '
          +lexeme+' '
          +(literal!=nullptr?literal->toString():"Nil")
          + std::string (", At (") + std::to_string (line)
          + std::string (", ") + std::to_string (column)
          + std::string (")");
}